<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/25
 * Time: 10:46
 */
namespace app\modules\api\controllers\beauty_cook;
use app\models\ContentComment;
use app\models\ContentWork;
use app\models\UploadConfig;
use app\models\UploadForm;
use app\modules\api\models\beauty_cook\ContentCommentForm;
use app\modules\api\models\beauty_cook\ContentWorkForm;

class ContentController extends Controller
{
    public function actionSave(){
        $form = new ContentWorkForm();
        $form->attributes = \Yii::$app->request->get();
        $model = new ContentWork();
        $form->model = $model;
        return $this->renderJson($form->save());

    }
    public function actionUploadImage()
    {
        $pingtai_id = $this->GetPingTai($this->store->id);
        $form = new UploadForm();
        $upload_config = UploadConfig::findOne(['store_id' => $pingtai_id]);
        $form->upload_config = $upload_config;
        $this->renderJson($form->saveImage('image'));
    }
    //点赞
    public function actionPrise(){
        $content_id = \Yii::$app->request->get('content_id');
        $res_praise = ContentWork::findOne(['content_id'=>$content_id]);
        $praise =$res_praise->praise+1;
        $result = ContentWork::UpdateAll(['praise'=>$praise],['content_id'=>$content_id]);
        if($result>0){
            return $this->renderJson([
                'code'=>0,
                'msg'=>'成功',
                'praise'=>$praise
            ]);
        }
    }
    public function actionSaveComment(){
        $form = new ContentCommentForm();
        $res= \Yii::$app->request->get();
//        var_dump($res);
        $model = new ContentComment();
        $form->model = $model;
        $form->type=$res['type'];
        $form->content_id=$res['content_id'];
        $form->comment_id=$res['comment_id'];
        $form->user_id=$res['user_id'];
        $form->praise=$res['praise'];
        $form->comment = $res['comment'];
        return $this->renderJson($form->save());
    }
    public function actionComment(){
        $content_id = \Yii::$app->request->get('content_id');
        $form = new ContentCommentForm();
        $form->content_id = $content_id;
        $res = $form->show();
        return $res;
    }
}